package com.nikkerball.apps.darkhorse.model.evaluation;

import com.nikkerball.apps.darkhorse.model.base.TouchableObject;
import com.nikkerball.apps.darkhorse.model.core.ClassYear;
import com.nikkerball.apps.darkhorse.model.evaluation.subject.SubjectEvaluation;
import com.nikkerball.apps.darkhorse.model.evaluation.topic.TopicEvaluation;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.Type;
import org.joda.time.LocalDate;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import java.util.List;

import static org.hibernate.annotations.CascadeType.*;

/**
 * Represents a Report Period
 */
@Entity
@Table(name = "EvaluationPeriod")
public class EvaluationPeriod extends TouchableObject {

    // ----- instance fields -----

    private ClassYear classYear;

    private LocalDate endDate;

    private LocalDate startDate;

    private List<SubjectEvaluation> subjectEvaluations;

    private List<TopicEvaluation> topicEvaluations;

    // ----- public methods -----

    @ManyToOne
    @JoinColumn(name = "classYear_Id", nullable = false)
    public ClassYear getClassYear() {
        return this.classYear;
    }

    public void setClassYear(ClassYear classYear) {
        this.classYear = classYear;
    }

    @Type(type = "org.joda.time.contrib.hibernate.PersistentLocalDate")
    @Column(name = "EndDate")
    public LocalDate getEndDate() {
        return this.endDate;
    }

    public void setEndDate(LocalDate endDate) {
        this.endDate = endDate;
    }

    @Type(type = "org.joda.time.contrib.hibernate.PersistentLocalDate")
    @Column(name = "StartDate")
    public LocalDate getStartDate() {
        return this.startDate;
    }

    public void setStartDate(LocalDate startDate) {
        this.startDate = startDate;
    }

    @OneToMany(mappedBy = "evaluationPeriod")
    @Cascade({MERGE, PERSIST, SAVE_UPDATE, DETACH, DELETE})
    public List<SubjectEvaluation> getSubjectEvaluations() {
        return this.subjectEvaluations;
    }

    public void setSubjectEvaluations(List<SubjectEvaluation> subjectEvaluations) {
        this.subjectEvaluations = subjectEvaluations;
    }

    @OneToMany(mappedBy = "evaluationPeriod")
    @Cascade({MERGE, PERSIST, SAVE_UPDATE, DETACH, DELETE})
    public List<TopicEvaluation> getTopicEvaluations() {
        return this.topicEvaluations;
    }

    public void setTopicEvaluations(List<TopicEvaluation> topicEvaluations) {
        this.topicEvaluations = topicEvaluations;
    }
}
